package com.wno704.system.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;

@Configuration
public class DataSourceConfig {

	//服保生产环境数据库
	@Bean(name = "dataSourceFbProd")
	@ConfigurationProperties("spring.datasource.druid.fbprod")
	public DataSource dataSourceFbProd(){
	    return DruidDataSourceBuilder.create().build();
	}
	
	@Bean(name = "jdbcTemplateFbProd")
	public JdbcTemplate jdbcTemplateFbProd(
	        @Qualifier("dataSourceFbProd") DataSource dataSource) {
	    return new JdbcTemplate(dataSource);
	}

	//服保报表环境数据库
	@Bean(name = "dataSourceFbReport")
	@ConfigurationProperties("spring.datasource.druid.fbreport")
	public DataSource dataSourceFbReport(){
		return DruidDataSourceBuilder.create().build();
	}

	@Bean(name = "jdbcTemplateFbReport")
	public JdbcTemplate jdbcTemplateFbReport(
			@Qualifier("dataSourceFbReport") DataSource dataSource) {
		return new JdbcTemplate(dataSource);
	}

	//调度生产环境数据库
	@Bean(name = "dataSourceDdProd")
	@ConfigurationProperties("spring.datasource.druid.ddprod")
	public DataSource dataSourceDdProd(){
	    return DruidDataSourceBuilder.create().build();
	}
	
	@Bean(name = "jdbcTemplateDdProd")
	public JdbcTemplate jdbcTemplateDdProd(
	        @Qualifier("dataSourceDdProd") DataSource dataSource) {
	    return new JdbcTemplate(dataSource);
	}

	//调度报表环境数据库
	@Bean(name = "dataSourceDdReport")
	@ConfigurationProperties("spring.datasource.druid.ddreport")
	public DataSource dataSourceDdReport(){
		return DruidDataSourceBuilder.create().build();
	}

	@Bean(name = "jdbcTemplateDdReport")
	public JdbcTemplate jdbcTemplateDdReport(
			@Qualifier("dataSourceDdReport") DataSource dataSource) {
		return new JdbcTemplate(dataSource);
	}

	//客调平台数据库
	@Bean(name = "dataSourceKdpt")
	@ConfigurationProperties("spring.datasource.druid.kdpt")
	public DataSource dataSourceKdpt(){
		return DruidDataSourceBuilder.create().build();
	}

	@Bean(name = "jdbcTemplateKdpt")
	public JdbcTemplate jdbcTemplateKdpt(
			@Qualifier("dataSourceKdpt") DataSource dataSource) {
		return new JdbcTemplate(dataSource);
	}

	//定时任务数据库
	@Bean(name = "dataSourceQuartz")
	@ConfigurationProperties("spring.datasource.druid.quartz")
	public DataSource dataSourceQuartz(){
	    return DruidDataSourceBuilder.create().build();
	}
	
	@Bean(name = "jdbcTemplateQuartz")
	public JdbcTemplate jdbcTemplateQuartz(
	        @Qualifier("dataSourceQuartz") DataSource dataSource) {
	    return new JdbcTemplate(dataSource);
	}

	//西宁大屏数据库
	@Bean(name = "dataSourceXndp")
	@ConfigurationProperties("spring.datasource.druid.xndp")
	public DataSource dataSourceXndp(){
		return DruidDataSourceBuilder.create().build();
	}

	@Bean(name = "jdbcTemplateXndp")
	public JdbcTemplate jdbcTemplateXndp(
			@Qualifier("dataSourceXndp") DataSource dataSource) {
		return new JdbcTemplate(dataSource);
	}

}
